<?php

use yii\helpers\Html;
use yii\helpers\Url;
use yii\grid\GridView;

/**
 * @var yii\web\View $this
 * @var yii\data\ActiveDataProvider $dataProvider
 * @var common\models\search\ApiItemSearch $searchModel
 */

$this->title = Yii::t('backend', 'Api Items');
$this->params['breadcrumbs'][] = $this->title;

if (isset($actionColumnTemplates)) {
    $actionColumnTemplate = implode(' ', $actionColumnTemplates);
    $actionColumnTemplateString = $actionColumnTemplate;
} else {
    Yii::$app->view->params['pageButtons'] = Html::a('<span class="glyphicon glyphicon-plus"></span> ' . 'New', ['create'], ['class' => 'btn btn-success']);
    $actionColumnTemplateString = "{view}  {update}  {delete}";
}
$actionColumnTemplateString = '<div class="action-buttons">' . $actionColumnTemplateString . '</div>';
?>
<div class="giiant-crud api-item-index">



    <?php \yii\widgets\Pjax::begin(['id' => 'pjax-main', 'enableReplaceState' => false, 'linkSelector' => '#pjax-main ul.pagination a, th a', 'clientOptions' => ['pjax:success' => 'function(){alert("yo")}']]) ?>

    <div class="clearfix crud-navigation">
        <div class="pull-left">
            <?= Html::a('<span class="glyphicon glyphicon-plus"></span> ' . 'New', ['create'], ['class' => 'btn btn-success']) ?>
        </div>

        <div class="pull-right">


            <?=
            \yii\bootstrap\ButtonDropdown::widget(
                [
                    'id' => 'giiant-relations',
                    'encodeLabel' => false,
                    'label' => '<span class="glyphicon glyphicon-paperclip"></span> ' . 'Relations',
                    'dropdown' => [
                        'options' => [
                            'class' => 'dropdown-menu-right'
                        ],
                        'encodeLabels' => false,
                        'items' => [
                            [
                                'url' => ['api-type/index'],
                                'label' => '<i class="glyphicon glyphicon-arrow-left"></i> ' . Yii::t('models', 'Api Type'),
                            ],
                            [
                                'url' => ['api-log/index'],
                                'label' => '<i class="glyphicon glyphicon-arrow-right"></i> ' . Yii::t('models', 'Api Log'),
                            ],

                        ]
                    ],
                    'options' => [
                        'class' => 'btn-default'
                    ]
                ]
            );
            ?>
        </div>
    </div>

    <hr/>

    <div class="table-responsive">
        <?= GridView::widget([
            'dataProvider' => $dataProvider,
            'pager' => [
                'class' => yii\widgets\LinkPager::class,
                'firstPageLabel' => 'First',
                'lastPageLabel' => 'Last',
            ],
            'filterModel' => $searchModel,
            'tableOptions' => ['class' => 'table table-striped table-bordered table-hover'],
            'headerRowOptions' => ['class' => 'x'],
            'columns' => [
                [
                    'class' => 'yii\grid\ActionColumn',
                    'template' => $actionColumnTemplateString,
                    'buttons' => [
                        'view' => function ($url, $model, $key) {
                            $options = [
                                'title' => Yii::t('cruds', 'View'),
                                'aria-label' => Yii::t('cruds', 'View'),
                                'data-pjax' => '0',
                            ];
                            return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, $options);
                        }
                    ],
                    'urlCreator' => function ($action, $model, $key, $index) {
                        // using the column name as key, not mapping to 'id' like the standard generator
                        $params = is_array($key) ? $key : [$model->primaryKey()[0] => (string)$key];
                        $params[0] = \Yii::$app->controller->id ? \Yii::$app->controller->id . '/' . $action : $action;
                        return Url::toRoute($params);
                    },
                    'contentOptions' => ['nowrap' => 'nowrap']
                ],
                'api_name',
                // generated by schmunk42\giiant\generators\crud\providers\core\RelationProvider::columnFormat
                [
                    'class' => yii\grid\DataColumn::class,
                    'attribute' => 'api_type_id',
                    'value' => function ($model) {
                        if ($rel = $model->apiType) {
                            return Html::a($rel->id, ['api-type/view', 'id' => $rel->id,], ['data-pjax' => 0]);
                        } else {
                            return '';
                        }
                    },
                    'format' => 'raw',
                ],
                'api_limit',

                [
                    'attribute' => 'api_route',
                    'value' => function ($model) {
                        return Html::a($model->api_name, $model->api_route, ['data-pjax' => 0,'target'=>'_blank']);
                    },
                    'format' => 'raw',
                ],

                'version',
                'api_params',
                'info',

                [
                    'attribute' => 'is_auth',
                    'value' => function ($model) {
                        return \common\enums\WhetherEnum::map()[$model->is_auth];
                    },
                    'format' => 'raw',
                ],
                [
                    'attribute' => 'status',
                    'value' => function ($model) {
                            return \common\enums\WhetherEnum::map()[$model->status];
                    },
                    'format' => 'raw',
                ],

//			'created_at',
//			'updated_at',
            ]
        ]); ?>
    </div>

</div>


<?php \yii\widgets\Pjax::end() ?>


